Assembly Language Programming 1
The 8086 Registers.
Data Registers.
A register is a temporary store for data ( a number) - a bit like a memory store location. If you were to look inside a register you would see a number in it...more specifically a binary number.
There are four 16-bit data registers. The upper and lower halves of the data registers are separately addressable. This means that each data register can be used as a single 16-bit register or as two 8-bit registers.
| 8-bit | 8-bit | ||
| AX | : | [AH] | [AL] |
| BX | : | [BH] | [BL] |
| CX | : | [CH] | [CL] |
| DX | : | [DH] | [DL] |
AX is sometimes called the Accumulator.
Pointer and Index Registers.
There are four 16-bit pointer and index registers :
| 16-bit | |||
| Stack Pointer | SP | : | [0111000111010100] |
| Base Pointer | BP | : | [1101001010011010] |
| Source Index | SI | : | [0000101001010100] |
| Destination Index | DI | : | [1110101010100101] |
Segment Registers
There are four 16-bit segment registers:
| 16-bit | |||
| Code Segment | CS | : | [0111000100010100] |
| Data Segment | DS | : | [1101001010111010] |
| Stack Segment | SS | : | [0110001001010100] |
| Extra Segment | ES | : | [1100011010100101] |
Status and Control Registers
There are two special 16-bit status and control registers:
| 16-bit | |||
| Instruction Pointer | IP | : | [0111010111100100] |
| Status word / Flags | : | [1101001010111010] |
A flag is a single bit (0 or 1) which indicates whether something is true or false.
The flag register [****VDITSZ*A*P*C] has 16 flags in it (not all are used):
| V | Overflow |
| D | Direction |
| I | Interrupt Enable |
| T | Trap |
| S | Sign |
| Z | Zero |
| A | Auxiliary Carry |
| P | Parity |
| C | Carry |
Assembly Language Instructions
Instructions consist of up to four parts :
| Label | Operator | Operand | Comment |
| (Optional) Used to identify the instruction. |
Basically, this is the type of instruction. | The data which is being operated upon. | (Optional) Enclosed in brackets. These are essential in Assembly Language programming! |
Example of a segment of Assembly Language Program :
| PUSH | AH | {Save contents of register AH} | |
| Initialise: | MOV | AH,1 | {For keyboard read instruction} |
| INT | 21H | {Call resident interrupt routine} | |
| CMP | AL,32 | ||
| JZ | Initialise | ||
| MOV | BL,AL | {Set aside} | |
| ADD | AL,1 | ||
| MOV | AH,2 | {For output instruction} | |
| MOV | DL,AL | ||
| INT | 21H | {Output new character} | |
| POP | AH | {Restore contents of AH} |
MOV (Move Byte or Word)
Syntax :
| MOV | destination, source |
MOV transfers data from the source operand to the destination operand.
It may be -
| Immediate Addressing | eg MOV AL,2 |
| between a register and memory | eg MOV BP, stacktop |
| between a register and a register | eg MOV AX,CX |
An example program (Using the Turbo Pascal Assembler)
| program Mov1; | ||||
| begin | ||||
| asm | {start of Assembly program} | |||
| mov ax,1 | {Place the number 1 into register AX} | |||
| {Put breakpoint here using <CTRL><f8> | ||||
| {and check the register window when break occurs} | ||||
| end | ||||
| end. | ||||
Enter and run this program.
Exercise
Can you figure this out?.....
In this program segment, data is moved about . What data ends up in which register?
| MOV | AL,20 |
| MOV | BL,5 |
| MOV | CH,AL |
| MOV | CL,BL |
| MOV | BL,3 |
| MOV | CH,BL |
What number ends up in :